#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define maxn 200005
const int mod = 10007;

int n;
vector<int> G[maxn];
int node_weight[maxn];
int maxans=0;
long long sumans=0;

int main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		cin>>node_weight[i];

	for(int u=1;u<=n;u++){
		if(G[u].size()<2) continue;
		int sa=0,sb=0,cmax=0,cmax2=0;
		for(int i=0;i<G[u].size();i++){
			int v=G[u][i];
			sa += node_weight[v]; 
			sa%=mod;
			sb += node_weight[v]*node_weight[v]; 
			sb%=mod;
			if(node_weight[v]>=cmax){
				cmax2=cmax;
				cmax=node_weight[v];
			}else if(node_weight[v]>=cmax2){
				cmax2=node_weight[v];
			}
		}
		sumans = (sumans+sa*sa-sb+mod)%mod;
		maxans = max(maxans, cmax*cmax2);
	}
	cout<<maxans<<" "<<sumans<<endl;

	return 0;
}